package com.myzl.web.controller.coal;

import com.myzl.coal.domain.AlarmEvent;
import com.myzl.coal.service.IAlarmEventService;
import com.myzl.common.annotation.Log;
import com.myzl.common.core.controller.BaseController;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.core.page.TableDataInfo;
import com.myzl.common.enums.BusinessType;
import com.myzl.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 事件Controller
 *
 * @author myzl
 * @date 2023-01-06
 */
@RestController
@RequestMapping("/coal/alarmEvent")
public class AlarmEventController extends BaseController
{
    @Autowired
    private IAlarmEventService alarmEventService;

    /**
     * 查询事件列表
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmEvent alarmEvent)
    {
        startPage();
        List<AlarmEvent> list = alarmEventService.selectAlarmEventList(alarmEvent);
        return getDataTable(list);
    }

    /**
     * 导出事件列表
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:export')")
    @Log(title = "事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmEvent alarmEvent)
    {
        List<AlarmEvent> list = alarmEventService.selectAlarmEventList(alarmEvent);
        ExcelUtil<AlarmEvent> util = new ExcelUtil<AlarmEvent>(AlarmEvent.class);
        util.exportExcel(response, list, "事件数据");
    }

    /**
     * 获取事件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(alarmEventService.selectAlarmEventById(id));
    }

    /**
     * 新增事件
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:add')")
    @Log(title = "事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmEvent alarmEvent)
    {
        return toAjax(alarmEventService.insertAlarmEvent(alarmEvent));
    }

    /**
     * 修改事件
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:edit')")
    @Log(title = "事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmEvent alarmEvent)
    {
        return toAjax(alarmEventService.updateAlarmEvent(alarmEvent));
    }

    /**
     * 删除事件
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:remove')")
    @Log(title = "事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(alarmEventService.deleteAlarmEventByIds(ids));
    }

    /**
     * 修改事件
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:handle')")
    @Log(title = "事件", businessType = BusinessType.UPDATE)
    @PutMapping("/handleOne")
    public AjaxResult handleOne(@RequestBody AlarmEvent alarmEvent)
    {
        return toAjax(alarmEventService.handleOne(alarmEvent));
    }

    /**
     * 修改事件
     */
    @PreAuthorize("@ss.hasPermi('coal:alarmEvent:handle')")
    @Log(title = "事件", businessType = BusinessType.UPDATE)
    @PutMapping("/handleMore")
    public AjaxResult handleMore(@RequestBody Long[] ids)
    {
        return toAjax(alarmEventService.handleMore(ids));
    }
}
